package com.aijk.web.admin.controller;

import net.viservice.editor.ueditor.UeditorActionEnter;
import net.viservice.editor.ueditor.UeditorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;

/**
 * <p> Ueditor插件后台功能 </p>
 * User: chendw
 * Date: 2016/11/21 11:30
 */
@Controller
@RequestMapping("/ueditor")
public class UeditorController extends BaseController {

    protected Logger logger = LoggerFactory.getLogger(getClass());

    @Resource
    private UeditorService ueditoreService;

    @RequestMapping(value = "execute")
    @ResponseBody
    public String execute(HttpServletRequest request, HttpServletResponse response, Model model) throws UnsupportedEncodingException {
        String rootPath = request.getServletContext().getRealPath("/");
        String resultMsg = new UeditorActionEnter(request, rootPath, this.ueditoreService).exec();

        logger.info("ueditor execute ... resultMsg:" + resultMsg);

        return resultMsg;
    }
}
